<?php


namespace app\admin\controller;


use app\common\controller\BaseController;
use EasyWeChat\Factory;
use EasyWeChatComposer\EasyWeChat;
use think\App;

class WxMiniProgram extends BaseController
{
    protected $wx;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $config = config('weixin.mini_program');
        $this->wx = Factory::miniProgram($config);
    }

    public function wxlogin()
    {
        $code = $this->request->get('code');
        if (empty($code)) {
            return $this->returnError(26);
        }
        try {
            $userInfo = $this->wx->auth->session($code);
            dd($userInfo);
        } catch (\Exception $ex) {
            return $this->returnException($ex);
        }
    }
}